/**  
* @Title:  LoginFormImpl.java
* @Package com.colldown.iservice.login.webc.impl
* @Description: TODO(用一句话描述该文件做什么)
* @author Wayne
* @date  2015-5-20 下午10:06:04
* @version V1.0  
* Update Logs:
* ****************************************************
* Name:
* Date:
* Description:
******************************************************
*/
package com.colldown.iservice.login.webc.impl;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.colldown.common.A_Tools;
import com.colldown.iservice.login.service.ILoginService;
import com.colldown.iservice.login.webc.ILoginForm;

/**
 * @ClassName: LoginFormImpl
 * @Description: TODO(登录模块实现类)
 * @author Wayne
 * @date 2015-5-20 下午10:06:04
 *
 */
@Controller
@RequestMapping("/loginForm")
public class LoginFormImpl implements ILoginForm {
	
	@Autowired
	ILoginService loginService;
	
	@Override
	@RequestMapping("/userLogin")
	public void userLogin(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String username = A_Tools.NullToStr(request.getParameter("username"));
		String password = A_Tools.NullToStr(request.getParameter("password"));
		Map paramMap = new HashMap();
		paramMap.put("USER_NAME", username);
		paramMap.put("PASS_WORD", password);
		int result = -1;
		try {
			result = this.loginService.login(paramMap);
			if(result==1){
				request.getSession().setAttribute("userSession", paramMap);
			}
			A_Tools.printJson(response, result+"");
		} catch (Exception e) {
			e.printStackTrace();
			A_Tools.printJson(response, result+"");
		}
	}
	@Override
	@RequestMapping("/userLogout")
	public void userLogout(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		request.getSession().removeAttribute("userSession");
		try {
			response.setContentType("text/html");
			response.sendRedirect("../");
			return;
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
